#ifndef FTPACCESSMANAGER_H
#define FTPACCESSMANAGER_H

#include <QObject>
#include <QUrl>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QFile>
#include <QFileInfo>
#include <QDebug>
#include <QEvent>

class ftpAccessManager : public QObject
{
    Q_OBJECT
public:
    explicit ftpAccessManager(QObject *parent = nullptr);
    virtual bool event(QEvent *event);

public:
    // 设置端口
    void setHostPortInfo(const QString &host, quint16 prot =21);
    void setUserPwdInfo(const QString &userName, const QString &pwd);

    // 下载路径
    void putFileFromClent(const QString &fileName, const QString &path);
    void getFileFromServer(const QString &fileName, const QString &path);

signals:
    /* 以下信号上传给界面 */
    void uploadProgressSignal(qint64, qint64);
    void downloadProgressSignal(qint64, qint64);
    void netErrorSignal(QNetworkReply::NetworkError);

private slots:
    //上传时的槽
    void uploadProgressSlot(qint64, qint64);
    void uploadFinishedSlot();
    void uploadErrorSlot(QNetworkReply::NetworkError);

    //下载时的槽
    void downloadProgressSlot(qint64, qint64);
    void downloadFinishedSlot();
    void downloadErrorSlot(QNetworkReply::NetworkError);

private:
    QUrl murl;
    QNetworkAccessManager mNetAccMgr;

    QFile *putFileData = nullptr;           //上传数据的文件指针
    QFile *getFileData = nullptr;

    QNetworkReply *putNetReply;            //上传的网络应答  QNetworkRequest请求
    QNetworkReply *getNetReply;            //下载数据的网络



};

#endif // FTPACCESSMANAGER_H
